package cn.com.yang.mq;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 
 * TODO
 * 注册多个生产者组
 * @author yangyijin
 * @since 2024年7月22日-下午7:02:04
 */
@Configuration
public class RocketMQConfig {
	@Value("${rocketmq.name-server:localhost:9876}")
	private String nameServer;

	@Bean(name = "producerGroup1")
	public DefaultMQProducer producerGroup1() throws Exception {
		DefaultMQProducer producer = new DefaultMQProducer("producerGroup1");
		producer.setNamesrvAddr(nameServer);
		producer.start();
		return producer;
	}

	@Bean(name = "producerGroup2")
	public DefaultMQProducer producerGroup2() throws Exception {
		DefaultMQProducer producer = new DefaultMQProducer("producerGroup2");
		producer.setNamesrvAddr(nameServer);
		producer.start();
		return producer;
	}
}
